
import { _decorator, Component, Node ,Graphics,RigidBody2D,PhysicsSystem2D,Label,Collider2D } from 'cc';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = Box
 * DateTime = Mon Apr 18 2022 16:54:55 GMT+0800 (中国标准时间)
 * Author = xiaopang125
 * FileBasename = Box.ts
 * FileBasenameNoExtension = Box
 * URL = db://assets/Box.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */
 
@ccclass('Box')
export class Box extends Component {
    // [1]
    // dummy = '';

    // [2]
    // @property
    // serializableDummy = 0;
    start () {
        this.getComponent(RigidBody2D).enabledContactListener = true;
        // PhysicsSystem2D.instance.gravity = v2();


        const ctx = this.node.getChildByName("Graphics").getComponent(Graphics);
        ctx.circle(0,0, 50);
        ctx.fillColor.fromHEX('#f8e8b0');
        ctx.fill();
        // const numNode:Node=new Node();
        // const label2 = this.node.getChildByName("Label");
        // label2.getComponent(Label).string="2";
        // numNode.parent=this.node;
        // [3]
    }
    public setNum(n){
        const label2 = this.node.getChildByName("Label");
        label2.getComponent(Label).string=n;
    }

    update (deltaTime: number) {
        if(this.node.position.y<-300||!this.getComponent(Collider2D)){
            this.node.destroy();
            console.log("delete");
            
        }
    }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.4/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.4/manual/zh/scripting/decorator.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.4/manual/zh/scripting/life-cycle-callbacks.html
 */
